package codeComposition;

import java.util.ArrayList;
import util.*;

public class FunctionElement extends ExpressionElement{
	
	public String funcName;
	ArrayList<Element> argus = new ArrayList<Element>();
	ArrayList<ExpressionElement> expressions = new ArrayList<ExpressionElement>();
	
	ConstructElement construct;
	
	public FunctionElement(String funcName, int tabNum){
		super(tabNum);
		this.funcName = funcName;
		this.tabNum = tabNum;
		construct = new ConstructElement(funcName);
	}
	
	public FunctionElement(String funcName, String argu, int tabNum){
		super(tabNum);
		this.funcName = funcName;
		argus.add((new ReferenceElement(argu)));
		this.tabNum = tabNum;
		construct = new ConstructElement(funcName, Translator.stringsToElements(argu));
	}
	
	public FunctionElement(String funcName, ArrayList<Element> argus, int tabNum){
		super(tabNum);
		this.funcName = funcName;
		this.argus = argus;
		this.tabNum = tabNum;
		construct = new ConstructElement(funcName, argus);
	}
	
	public FunctionElement(ConstructElement ce, int tabNum){
		super(tabNum);
		this.funcName = ce.func;
		this.argus = ce.argus;
		this.tabNum = tabNum;
		construct = ce;
	}
	
	
	public void add(ExpressionElement ee){
		this.expressions.add(ee);
	}
	
	public int getTabNum(){
		return tabNum;
	}
	
	public String toString(){
		String str = tabStr;
		str = str + "def " + construct.getRawString() +":";
		if(expressions.size() == 0){
			str = str + "\n" + tabStr + "\tpass\n\n";
			return str;
		}
		str = str + "\n";
		for(ExpressionElement ee:expressions){
			ee.setTabNum(tabNum + 1);
			str = str + ee.toString();
		}
		str += "\n";
		return str;
	}
	
	public static void main(String[] argvs) {
		ArrayList<Element> argus = new ArrayList<Element>();
		ReferenceElement argu1 = new ReferenceElement("argu1");
		ReferenceElement argu2 = new ReferenceElement("argu2");
//		argus.add(argu1);
//		argus.add(argu2);
		argus.add(new VarAssignElement(argu1, argu2));

		ConstructElement ce5 = new ConstructElement("func");
		ConstructElement ce6 = new ConstructElement("func", 0);
		ConstructElement ce7 = new ConstructElement("func", argus);
		ConstructElement ce8 = new ConstructElement("func", argus, 0);
		
		FunctionElement func5 = new FunctionElement(ce5, 1);
		FunctionElement func6 = new FunctionElement(ce6, 0);
		FunctionElement func7 = new FunctionElement(ce7, 1);
		FunctionElement func8 = new FunctionElement(ce8, 0);
		
		String[] sl = {"var1", "var2", "var3"};
		String to = new String("to");
		ListAssighElement lae = new ListAssighElement(sl, to);

		func5.add(lae);
		System.out.println(func5.toString() + func6.toString()
				+ func7.getRawString() + func8.toString());
	}
}
